﻿@model BankData  
<link href="@Url.Content("~/Scripts/Lib/Autocomplete/jquery.autocomplete.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/Lib/Autocomplete/jquery.autocomplete.js")" type="text/javascript"></script>

<script language="javascript" type="text/javascript">

    function refundmentSetCustomerCode(data) {
        var container = $("#addrefundmentcontainer");
        $("#CustomerCode", container).val(data.CustomerCode);
    }

    function clearCustomerCode(data) {
        var container = $("#addrefundmentcontainer");
        $("#CustomerCode", container).val("");
    }

    //获取客户编号
    function getcustomers() {
        $.ajax({
            type: "POST",
            url: '@Url.Content("~/Customer/GetCustomCodeList")',
            contentType: "application/json",
            dataType: "json",
            success: function (msg) {

                var mssege = "[";
                $.each(msg, function (index, content) {
                    mssege += "{CustomerCode: \"" + content + "\" },";
                });
                mssege = mssege.substring(0, mssege.length - 1);
                mssege += "]";
                var customers = eval(mssege);
                autocomplate(customers);
            }
        });

    }

    //自动获取下拉列表
    function autocomplate(customers) {
        $("#CustomerCode").autocomplete(customers, {
            max: 20,
            scroll: true,
            minChars: 0,
            width: 200,
            scrollHeight: 300,
            matchContains: true,
            formatItem: function (row, i, max) {
                if (row.CustomerCode == null) {
                    return "";
                }
                return row.CustomerCode;
            },
            formatResult: function (row) {
                if (row.CustomerCode == null) {
                    return "";
                }
                return row.CustomerCode;
            }
        }).result(function (event, data, formatted) {
            $.post('@Url.Content("~/Customer/GetCustomNameByCode")', { customerCode: formatted }, function (result) {
                $('#CustomerName', "#addrefundmentcontainer").val(result);
                $("input[name='CustomerName']:hidden", "#addrefundmentcontainer").val(result);
            }
            );

        });
    }

    $(document).ready(function () {
        //        $("#addrefundmentcontainer div[valuefield='CustomerName'] a").eq(0).click();
        getcustomers();
    });

</script>
@using (Html.BeginForm())
{
    <div id="addrefundmentcontainer">
        @Html.Hidden("Id", ViewData["Id"])
        @Html.Hidden("FinanceCheckOut", "true")
        <div class="layout-onecolumn">
            <div class="editor-label">
                @Html.LabelFor(model => model.CustomerName)
            </div>
            <div class="editor-field">
                @*@Html.SearchFor(model => model.CustomerName, s => EntityCache<Customer>.FindByKey(m => m.CustomerName, s).CustomerName, "Customer", "CustomerName", "CustomerName", "refundmentSetCustomerCode")*@
                @*@Html.SearchForCustomer(m => m.CustomerName, "Customer", "CustomerListByJson", "CustomerName", "CustomerName", succHandler: "refundmentSetCustomerCode", clearHandler: "clearCustomerCode")*@
@*                @Html.SearchForCustomer(m => m.CustomerName, "Customer", "CustomerList", "CustomerName", "CustomerName", succHandler: "refundmentSetCustomerCode", clearHandler: "clearCustomerCode")
*@                @Html.ValidationMessageFor(model => model.CustomerName)
            </div>
        </div>
        <div class="layout-onecolumn">
            <div class="editor-label">
                @Html.LabelFor(model => model.CustomerCode)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.CustomerCode, new Dictionary<string, object>() { /*{ "readonly", "readonly" },*/{ "id", "CustomerCode" } })
                @Html.ValidationMessageFor(model => model.CustomerCode)
            </div>
        </div>
    </div>
}
